<template>
  <div id="Login">
    <div class="container-fluid">
      <div class="row bg">
        <div class=" col-lg-offset-8 col-lg-3 col-lg-offset-8 col-md-4 col-lg-offset-7 col-sm-5 form">
          <div style="margin: 20px 0px 40px 0px">
            <h3 style="color: #FFFFFF;font-weight: bolder">客户关系管理系统 V1.0</h3>
          </div>
          <form class="form-horizontal" id="loginForm">
            <div class="form-group">
              <label for="staffEmail" class="col-sm-4 control-label" style="color: #FFFFFF">邮箱</label>
              <div class="col-sm-8">
                <input @blur="checkStaffEmail" v-model="staff.staffEmail" type="text" class="form-control" id="staffEmail" placeholder="请输入邮箱">
              </div>
            </div>
            <div class="form-group">
              <label for="staffPassword" class="col-sm-4 control-label" style="color: #FFFFFF">密码</label>
              <div class="col-sm-8">
                <input @blur="checkStaffPassword()" v-model="staff.staffPassword" type="password" class="form-control" id="staffPassword" placeholder="请输入密码">
              </div>
            </div>
<!--            <div class="form-group">-->
<!--              <label for="validateCode" class="col-sm-4 control-label" style="color: #FFFFFF">验证码</label>-->
<!--              <div class="col-sm-4">-->
<!--                <input type="text" class="form-control" id="validateCode" placeholder="请输入验证码">-->
<!--              </div>-->
<!--              <div class="col-sm-4">-->
<!--                <img src="images/yzm.jpg" alt="" width="75px" height="35px">-->
<!--              </div>-->
<!--            </div>-->
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">

                <div class="checkbox">
<!--                  <label>-->
<!--                    <input type="checkbox"><span style="color: #FFFFFF">记住我</span>-->
<!--                  </label>-->
                </div>
                <div class="text-center">
                </div>
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10 text-center">
                <button id="submitBtn" v-on:click="toLogin" class="btn btn-success" style="width: 50%;">登录</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      staff: {
          staffEmail:"",
          staffPassword:""
        }
    }
  },
  methods:{
    checkStaffEmail(){
      if (this.staff.staffEmail == ""){
        this.$message({
          showClose: true,
          message: '账户不能为空',
          type: 'error'
        });
        return false;
      }
      return true
    },
    checkStaffPassword() {
      if (this.staff.staffPassword == "") {
        this.$message({
          showClose: true,
          message: '密码不能为空',
          type: 'error'
        });
        return false;
      }
      return true;
    },
    toLogin() {
      if (this.checkStaffEmail()){
        if (this.checkStaffPassword()){
          this.$axios.post("/staff/login", this.staff).then(
            response => {
              // console.log(response.data.data.roles)
              this.$store.commit("SET_TOKEN", response.data.data.token)
              this.$store.commit("SET_STAFFINFO", response.data.data.staff)
              this.$router.replace("/MemuBar/PersonalInf")
              this.$message({
                showClose: true,
                message: response.data.message,
                type: 'success'
              });
            }).catch({

          })
        }
      }

    }
  },
  created() {
  }
}
</script>

<style scoped>
.bg{
  height: 720px;
  background-image:url(../../static/img/images/chenlong.png);
  background-size:cover;
}

.form{
  height: 400px;
  padding: 40px;
  margin-top: 105px;
  background: rgba(255,255,255,0.2);
}
</style>
